import java.util.Scanner;

public class Test {
    public static void main(String[] args) {
        int[] array = {1,2,3,4,5,6};
        Scanner scanner = new Scanner(System.in);
        System.out.print("请输入要查找的数字：");
        int n = scanner.nextInt();
        new Test().binarySearch(array,n);
    }

    void binarySearch(int[] array,int n){
        int lift = 0;
        int right = array.length - 1;
        while (lift <= right){
            int mid = (lift + right) / 2;
            if (array[mid] < n){
                lift = mid + 1;
            }
            else if (array[mid] > n){
                right = mid - 1;
            }
            else {
                System.out.println("找到下标为：" + mid);
                return;
            }
        }
        System.out.println("找不到");
    }
}


